/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = was_ejb_parse_req.c                                */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/11 by jikw                                 */
/*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include <corba/corba_comm.h>
#include <corba/corba_core.h>
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frbyte_buffer.h"
#include "frlist.h"
#include "frreport_comm.h"
#include "apmtest_cunit.h"
#include "apmtest_comm.h"

#include "../../../src/module/corba/config.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

extern int was_ejb_parse_req(corba_session *p_st_session_private
                    , Frreport_body_data *p_st_body_data);

extern L7session_corba_private* __corba_private_create(void);
extern corba_session* __corba_session_create(void);

static void case1(void)
{
    corba_session *p_st_session_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    //char *p_key = NULL;
    //int i_pos = 0;
    int i_ret = 0;

    i_ret = was_ejb_parse_req(p_st_session_private, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    return;
}

static void case2(void)
{
    corba_session *p_st_session_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;
    int i_ret = 0;

    p_st_session_private = __corba_session_create();

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_conn, 0x00, sizeof(Conntrack));

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
    p_st_conn->st_l7_analyzer.p_st_l7_module = (L7_module *)"1";

    p_st_body_data = frreport_body_new_l7(p_st_conn);

    i_ret = was_ejb_parse_req(p_st_session_private, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    corba_session_destroy(p_st_session_private);
    frfree(p_st_conn);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case3(void)
{
    corba_session *p_st_session_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    //Conntrack *p_st_conn = NULL;
    //char *p_key = NULL;
    //int i_pos = 0;
    int i_ret = 0;

    p_st_session_private = __corba_session_create();
    p_st_session_private->p_st_private = __corba_private_create();

    i_ret = was_ejb_parse_req(p_st_session_private, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    corba_session_destroy(p_st_session_private);

    return;
}

static void case4(void)
{
    corba_session *p_st_session_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;

    p_st_session_private = __corba_session_create();
    p_st_session_private->p_st_private = __corba_private_create();

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_conn, 0x00, sizeof(Conntrack));

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
    p_st_conn->st_l7_analyzer.p_st_l7_module = (L7_module *)"1";

    p_st_body_data = frreport_body_new_l7(p_st_conn);

    i_ret = was_ejb_parse_req(p_st_session_private, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    frfree(p_st_conn);
    frreport_body_free(&p_st_body_data);
    corba_session_destroy(p_st_session_private);

    return;
}

static void case5(void)
{
    corba_session *p_st_session_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;

    p_st_session_private = __corba_session_create();
    p_st_session_private->p_st_private = __corba_private_create();
    p_st_session_private->p_st_private->p_title = frstrdup("resolve_complete_info");

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_conn, 0x00, sizeof(Conntrack));

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
    p_st_conn->st_l7_analyzer.p_st_l7_module = (L7_module *)"1";

    p_st_body_data = frreport_body_new_l7(p_st_conn);

    i_ret = was_ejb_parse_req(p_st_session_private, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    frfree(p_st_conn);
    frreport_body_free(&p_st_body_data);
    corba_session_destroy(p_st_session_private);

    return;
}

static void case6(void)
{
    corba_session *p_st_session_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;

    p_st_session_private = __corba_session_create();
    p_st_session_private->p_st_private = __corba_private_create();
    p_st_session_private->p_st_private->p_title = frstrdup("_get_char");

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_conn, 0x00, sizeof(Conntrack));

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
    p_st_conn->st_l7_analyzer.p_st_l7_module = (L7_module *)"1";

    p_st_body_data = frreport_body_new_l7(p_st_conn);

    i_ret = was_ejb_parse_req(p_st_session_private, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    frfree(p_st_conn);
    frreport_body_free(&p_st_body_data);
    corba_session_destroy(p_st_session_private);

    return;
}

static void case7(void)
{
    corba_session *p_st_session_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    char *p_key_address = (char *)"\x4a\x4d\x42\x49\x00\x00\x00\x12\x47\x73\xe3\xaa\x37\x64\x30\x62\x63\x37\x37\x33\x65\x33\x61\x61\x66\x63\x33\x34\x00\x00\x00\x24\x00\x00\x00\x43\x49\x45\x4a\x50\x02\x00\xcb\xb2\xfc\xc0\x07\x73\x65\x72\x76\x65\x72\x31\x03\x45\x4a\x42\x00\x00\x00\x29\xac\xac\x00\x02\x00\x01\x11\x1e\x00\x00\x00\x45\x4a\x42\x53\x79\x73\x74\x65\x6d\x23\x45\x4a\x42\x2e\x6a\x61\x72\x23\x48\x65\x6c\x6c\x6f\x53\x65\x73\x73\x69\x6f\x6e";
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;
    //Frreport_data *p_st_report_data = NULL;
    //char *p_show_data = NULL;
    //unsigned int ui_show_data_len = 0;

    p_st_session_private = __corba_session_create();
    p_st_session_private->p_st_private = __corba_private_create();
    p_st_session_private->p_st_private->p_title = frstrdup("_get_char");
    p_st_session_private->p_was_function = frstrdup("_get_char");
    p_st_session_private->p_key_address = (char *)frmalloc(104);
    memcpy(p_st_session_private->p_key_address, p_key_address, 103);
    p_st_session_private->p_key_address[103] = '\0';

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_conn, 0x00, sizeof(Conntrack));

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
    p_st_conn->st_l7_analyzer.p_st_l7_module = (L7_module *)"1";

    p_st_body_data = frreport_body_new_l7(p_st_conn);

    i_ret = was_ejb_parse_req(p_st_session_private, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    //p_st_report_data = frreport_data_l7_new(FRREPORT_TYPE_L7DATA_RESP);
    //frreport_data_add_body(p_st_report_data, p_st_body_data);
    //frdbg_report_data_format(p_st_report_data, FR_YES, &p_show_data, &ui_show_data_len);
    //printf("p_show_data:[%s]\n", p_show_data);

    frfree(p_st_conn);
    //frreport_data_free(&p_st_report_data);
    //frfree(p_show_data);
    corba_session_destroy(p_st_session_private);
    frreport_body_free(&p_st_body_data);

    return;
}

int add_suite_was_ejb_parse_req(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" was_ejb_parse_req()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", case1);
    CU_add_test(pSuite, "case2", case2);
    CU_add_test(pSuite, "case3", case3);
    CU_add_test(pSuite, "case4", case4);
    CU_add_test(pSuite, "case5", case5);
    CU_add_test(pSuite, "case6", case6);
    CU_add_test(pSuite, "case7", case7);

    return FR_SUCC;
}


